<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 300px;
            height: 300px;
            border: 1px solid #000;
            margin: auto;
            float: left;
            margin-right: 20px;
            font-size: 36px;
            line-height: 300px;
            text-align: center;
        }
    </style>
</head>

<body>
<div class="one">十六进制</div>
<div class="two">RGB</div>

<script>
    function getRandomColor(flag) {
        if (flag) {
            let str = '';
            for (var i = 0; i < 6; i++) {
                str += Math.floor(Math.random() * 16).toString(16);

            }
            return '#' + str.toLowerCase()
        } else {
            let r = parseInt(Math.random() * 256)
            let g = parseInt(Math.random() * 256)
            let b = parseInt(Math.random() * 256)
            return `rgb(${r},${g},${b})`
        }

    };
    let one = document.querySelector('.one');
    let two = document.querySelector('.two');
    one.style.background = getRandomColor(true);
    two.style.background = getRandomColor(false);

    console.log(getRandomColor(true)); //#fabc12
    console.log(getRandomColor(false)); //rgb(128,65,88)
</script>
<script>
    function colo(){
        var a=parseInt(Math.random()*256);
        var b=parseInt(Math.random()*256);
        var c=parseInt(Math.random()*256);
        if(a<16){
            a="0"+a.toString(16);
        }else{
            a=a.toString(16);
        }
        if(b<16){
            b="0"+b.toString(16);
        }else{
            b=b.toString(16);
        }
        if(c<16){
            c="0"+c.toString(16);
        }
        else{
            c=c.toString(16);
        }
        return console.log("#"+a+b+c);
    }
    colo();

</script>

<script>
    // function Random(max,min){
    //
    // }
    var a = 20;
    function foo(){
        // console.log(a);
        var a = true
    }
    foo();
</script>
</body>

</html>
